function addMessage(msg) {
    $("#chat-msg-area").append("" +
        "<div class='chat-in'>" +
            "<span class='chat-time'></span>" +
            "<strong class='chat-user'>" + msg.from + "</strong>"+
            "<div class='chat-text'>" + msg.text + "</div>" +
        "</div>");
}

fromServSocket.onmessage = function(event) {
    var msg = $.parseJSON(event.data);
    if (msg.type == "ChannelMessage") {
        addMessage(msg);
    }

    if (msg.type == "ChangeStatusMessage") {
        var user = msg.user;
        var status = msg.status;
        var userStatusSelector = $("#status_" + user);
        userStatusSelector.removeAttr('class');
        userStatusSelector.attr('class', 'icofont-certificate color-'+ status);
    }

    if (msg.type == "MemberJoinedChannelMessage") {
        $("#contact-list").append(buildMemberItem(msg));
    }

    if (msg.type == "MemberLeftChannelMessage") {
        $("#status_" + msg.name).closest("li").remove();
    }

    //$("#empty").before("<p> <span style='color: blue'> " + msg.from + "</span>&gt&nbsp" + msg.text + "</p>");
};


toServSocket.onmessage = function(event) {
};

function sendMessage() {
    var message = $("#message_text").val();
    toServSocket.send(message);
    $("#message_text").val("");
}
